package com.vint.mi;

/**
 * 1.easy
 * 2.done
 * 比较大数大小或相加
 */
public class Mi19 {
    public static String solution(String line){
        if(line.contains("<")){
            String[] src = line.split("<");
            return compStr(src[1],src[0]);
        }else if(line.contains(">")){
            String[] src = line.split(">");
            return compStr(src[0],src[1]);
        }else{
            String[] src = line.split("\\+");
            return addStr(src[0],src[1]);
        }
    }

    public static String compStr(String str1, String str2){
        if(str1.length()<str2.length()){
            return "N";
        }
        if(str1.length()>str2.length()){
            return "Y";
        }
        int length = str1.length();
        char[] s1 = str1.toCharArray();
        char[] s2 = str2.toCharArray();
        for(int i=0;i<length;i++){
            if(s1[i]>s2[i]){
                return "Y";
            }else if(s1[i]<s2[i]){
                return "N";
            }else{
                if(i==length-1){
                    return "N";
                }
            }
        }
        return "N";
    }
    public static String addStr(String str1, String str2){
        int length1 = str1.length();
        int length2 = str2.length();
        if(length1<length2) {
            return addStr(str2, str1);
        }
        char[] s1 = str1.toCharArray();
        char[] s2 = str2.toCharArray();
        StringBuffer sb = new StringBuffer();
        int i,j;
        int carry = 0;
        int sum = 0;
        int left = 0;
        for(i = length1 - 1, j = length2 - 1; j >= 0; i--,j--){
            sum = s1[i] + s2[j] + carry - 2 * '0';
            carry = sum / 10;
            left = sum % 10;
            sb.append(String.valueOf(left));
        }
        for(i = length1 - length2 - 1; i >= 0; i--){
            sum = s1[i] + carry -  '0';
            carry = sum / 10;
            left = sum % 10;
            sb.append(String.valueOf(left));
        }
        if(carry == 1){
            sb.append("1");
        }
        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        String ex1 = "51111111111111111+23";
        String ex2 = "798876108959508902791396730547>788499852767910683563323887278";
        System.out.println(solution(ex1));
        System.out.println(solution(ex2));
    }
}
